<#include "/WEB-INF/default/fragment/header.ftl">
<body>

<#include "/WEB-INF/default/fragment/nav.ftl">
<div class="clearfix">
<div class="container1 fl">
  <img src="${request.contextPath}/assets/images/login_ico01.png">
</div>
<div class="container02 fl">
<div class="container container2">
  <div class="tms-logo"><img class="center-block" src="${request.contextPath}/assets/images/logo.png" alt=""></div>
  <form class="form j_login_form" action="" method="post">
    <fieldset>
      <div class="form-group">
        <label for="exampleInputEmail1">邮箱</label>
        <input type="text" class="form-control" id="exampleInputEmail1" name="email" placeholder="Email">
        <p class="help-block"></p>
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">密码</label>
        <input type="password" class="form-control" id="exampleInputPassword1" name="passwd" placeholder="Password">
        <p class="help-block"></p>
      </div>
      <div class="checkbox">
        <label><input type="checkbox" name="remeberMe" value="1"> 记住我</label>
      </div>
      <button type="submit" class="btn btn-success btn-block j_submit_button" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> 正在验证">登录</button>
    </fieldset>
  </form>
</div>
<script>
$(document).on('submit', '.j_login_form', function() {
  var param = $('.j_login_form').serialize();
  param = param + '&struts.enableJSONValidation=true';
  $('.j_submit_button').button('loading');
  $.post('${request.contextPath}/login_post.action', param, function(data, textStatus, xhr) {
    $('.j_submit_button').button('reset');

    // { "fieldErrors": {"email":["\u7528\u6237\u540D\u4E0D\u80FD\u4E3A\u7A7A"],"passwd":["\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A"]}}
    if(data['fieldErrors'] != null) {
      for (var i in data['fieldErrors']) {
        $('input[name="'+i+'"]').next().html(data['fieldErrors'][i]);
      }
      return;
    }

    if (data['status'] === 1) {
      window.location.href = '${request.contextPath}/index.action';
    }
    if (data['status'] === 0) {
      alert(data['message']);
    }

    console.log(data);
  });
  return false;
});
</script>
</div>
</div>
</body>
<#include "/WEB-INF/default/fragment/footer.ftl">
